//
//  TZeditorViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "TZeditorViewCell.h"
#import "TZdetailCell.h"

@interface TZeditorViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)UICollectionView *myCollectionView;
@property(nonatomic,retain)NSMutableArray *allmodelarray;

@property(nonatomic,retain)UIImageView *myHeadView;
@end

@implementation TZeditorViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatSubViews];
        self.allmodelarray = [NSMutableArray array];
    }


    
    return self;
    
}


//创建cell 视图(collectionView)
-(void)creatSubViews
{
    
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 15;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowLayout.itemSize = CGSizeMake((TZWIDTH-40)/3,TZWIDTH *0.5);
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,TZWIDTH,TZWIDTH *0.5) collectionViewLayout:flowLayout];
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.myCollectionView];
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    self.myCollectionView.showsVerticalScrollIndicator = YES;
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;

    
    

    
    
    //注册cell
    [self.myCollectionView registerClass:[TZdetailCell class] forCellWithReuseIdentifier:@"TZdetailCell"];
}


//collectionView 协议方法


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.allmodelarray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TZeditorModel *model = [self.allmodelarray objectAtIndex:indexPath.row];
//    NSString *Str = model.title;
    
//    NSLog(@"22323%@",Str);
    static NSString *cellId = @"TZdetailCell";
    
    TZdetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    cell.Model = model;
    cell.backgroundColor = [UIColor whiteColor];
    
    
    return cell;
    
}




//collectionView 点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{
    TZeditorModel *model = self.allmodelarray[indexPath.row];
    
    [self.picTableCellDelegate JumpToAlbumView:model.albumId :model.title :model.trackId :model];
    

}


//重写字典 给数组赋值
-(void)setMyDic:(NSMutableDictionary *)myDic
{
    [self.allmodelarray removeAllObjects];
    
//    NSLog(@"1111111%@",myDic);
    NSMutableArray *Array = myDic[@"list"];
    for (NSMutableDictionary *dic in Array) {
        TZeditorModel *model = [[TZeditorModel alloc]init];
        [model setValuesForKeysWithDictionary:dic];
        [self.allmodelarray addObject:model];
    }
  
    [self.myCollectionView reloadData];

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
